package com.softoa.serviceImp;

import com.softoa.mapper.HistoryNewsMapper;
import com.softoa.mapper.NewsMapper;
import com.softoa.pojo.Historynews;
import com.softoa.pojo.News;
import com.softoa.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

/**
 * Service实体类
 */
@Service
public class NewsServiceImp implements INewsService {
    @Autowired
    NewsMapper newsMapper;
    @Autowired
    HistoryNewsMapper historyNewsMapper;

    @Override
    public int newsSave(News news) {
        Historynews historynews=new Historynews();
        java.util.List<News> ns =newsMapper.newsSelectList(news);
        for(News n:ns) {
            historynews.setNewsId(n.getNewsId());
            historynews.setHistoryNewsText(n.getNewsText());
            historynews.setSaveUserId(news.getSendUserId());
            Date date = new Date();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            df.setTimeZone(TimeZone.getTimeZone("GMT+8"));
            historynews.setSaveTime(Timestamp.valueOf(df.format(date)));
            String de = "";
            de += n.getNewsFormat() + "/" + n.getNewsSendTime() + "/" + n.getSessionId() + "/" + n.getAcceptUserId() + "/" + n.getSendUserId();
            historynews.setDescirbe(de);
            historyNewsMapper.historyNewsInsert(historynews);
        }
        return 0;
    }
}
